package com.android.videotest;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.util.Pair;

import java.util.List;

import cn.jzvd.JzvdStd;

public class AutoPlayNextVideo extends JzvdStd {
    int mPlayIndex = 0;  //剧集标识
    List<Pair<String, String>> mUrls;

    public AutoPlayNextVideo(Context context) {
        super(context);
    }

    public AutoPlayNextVideo(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public void setUrls(List<Pair<String, String>> urls) {
        mUrls = urls;
    }

    public void setPlayIndex(int playIndex) {
        mPlayIndex = playIndex;
    }

    /**
     * 自动播放下一集
     * 若果需要手动选集 自定义Ui定义出剧集列表 调用相关changeUrl
     */
    @Override
    public void onAutoCompletion() {
        super.onAutoCompletion();
        if (mUrls == null) {
            if (BuildConfig.DEBUG) {
                Log.d(this.getClass().getName(), "onAutoCompletion: ");
            }
            return;
        }
        mPlayIndex++;
        if (mPlayIndex < mUrls.size()) {
            Pair<String, String> pair = mUrls.get(mPlayIndex);
            setUp(pair.first, pair.second);
            startVideo();
        }
    }
}
